#ifndef DIALOG_H
#define DIALOG_H

//#include   <QChartView>
//#include   <QSplineSeries>
//using namespace QtCharts;
#include<QtCharts>

#include <QDialog>
#include "scatter.h"
#include "pch.h"
#include "mychartview.h"


namespace Ui {
    class Dialog;
}
class QTimer;
class QextSerialPort;
class QextSerialEnumerator;

class Dialog : public QDialog
{
    Q_OBJECT

public:
    explicit Dialog(QWidget *parent = 0);
    ~Dialog();

protected:
    void changeEvent(QEvent *e);
    void wheelEvent(QWheelEvent *event);

private Q_SLOTS:
    void onPortNameChanged(const QString &name);
    void onBaudRateChanged(int idx);
    void onParityChanged(int idx);
    void onDataBitsChanged(int idx);
    void onStopBitsChanged(int idx);
    void onQueryModeChanged(int idx);
    void onMaxXSizeChanged(int idx);
    void onMaxYSizeChanged(int idx);
    void onGridLengthChanged(int idx);
    void onMapScaleChanged(int idx);

    void onTimeoutChanged(int val);
    void onOpenCloseButtonClicked();
    void onSendButtonClicked();
    void onReadyRead();
    void onUpdateStatus();
    void onPortAddedOrRemoved();

    void initChart();
    void plotScatterOfSLAM(uint16_t *xSlam, uint16_t *ySlam); // the main time for plot: parse comm date and plot
    void plotLineOfDrone(uint16_t *xDrone, uint16_t *yDrone);

private:
    Ui::Dialog *ui;
    QTimer *timerReadData, *timerUpdateStatus;
    QextSerialPort *port;
    QextSerialEnumerator *enumerator;
    Scatter *scatter;
    QChart *chart;
    QLineSeries *lineSeries;
    QScatterSeries *scatterSeries;
    MyChartView * myChartView;


    int max_x_size, max_y_size, map_scale;
    double grid_length;
    pos_pack pp;   //

    uint16_t *xDrone, *yDrone;

};

#endif // DIALOG_H
